package com.gupao.study.composite;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class Composite extends Component {

    private String name;
    private int level;
    private List<Component> list = new ArrayList<Component>();

    public Composite(String name, int level) {
        this.name = name;
        this.level = level;
    }

    public void addComponent(Component c){
        list.add(c);
    }

    public void print() {
        System.out.println(getName());
        for(Component c:list){
            if(this.level!=0){
                for(int i=0;i<level;i++){
                    System.out.print("  ");
                }
            }
            c.print();
        }
    }
}
